package com.yungu.swift.admin.route.system;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yungu.swift.admin.base.CurrentUser;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.model.PageVo;
import com.yungu.swift.base.model.admin.AdminPageParam;
import com.yungu.swift.base.model.admin.AdminParam;
import com.yungu.swift.base.model.admin.AdminUuidParam;
import com.yungu.swift.system.sys.model.dto.SysBusinessOrganizationDto;
import com.yungu.swift.system.sys.model.param.AdminBusinessCityAddParam;
import com.yungu.swift.system.sys.model.param.AdminBusinessCityDelParam;
import com.yungu.swift.system.sys.model.vo.BusinessVo;
import com.yungu.swift.system.sys.service.SysBusinessCityService;
import com.yungu.swift.system.sys.service.SysBusinessOrganizationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : cuixiuyin
 * @date : 2019/6/17
 */
@RestController
@RequestMapping("/admin/v1/system/business")
@Api(value = "【系统服务-业务设置中心】", tags = "业务范围管理")
public class BusinessAdmin {

    @Reference
    private SysBusinessOrganizationService sysBusinessOrganizationService;
    @Reference
    private SysBusinessCityService sysBusinessCityService;

    @RequestMapping(value = "/queryPage", method = RequestMethod.POST)
    @ApiOperation(value = "业务分页查询", httpMethod = "POST")
    public ResponseData<PageVo<BusinessVo>> queryPage(@RequestBody AdminPageParam adminPageParam, @CurrentUser AdminParam adminParam) {
        return sysBusinessOrganizationService.queryPageAdmin(adminPageParam);
    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ApiOperation(value = "新增业务", httpMethod = "POST")
    public ResponseData<Boolean> add(@RequestBody AdminUuidParam uuidParam) {
        SysBusinessOrganizationDto businessDto = new SysBusinessOrganizationDto();
        businessDto.setBusinessUuid(uuidParam.getUuid());
        businessDto.setAppid(uuidParam.getAppid());
        businessDto.setCreateBy(uuidParam.getUserUuid());
        businessDto.setLevel(1);
        return sysBusinessOrganizationService.add(businessDto);
    }

    @RequestMapping(value = "/addCity", method = RequestMethod.POST)
    @ApiOperation(value = "新增关联城市", httpMethod = "POST")
    public ResponseData<Boolean> addCity(@RequestBody AdminBusinessCityAddParam businessCityAddParam) {
        return sysBusinessCityService.addAppCity(businessCityAddParam);
    }

    @RequestMapping(value = "/delCity", method = RequestMethod.POST)
    @ApiOperation(value = "删除关联城市", httpMethod = "POST")
    public ResponseData<Boolean> delCity(@RequestBody AdminBusinessCityDelParam cityDelParam) {
        return sysBusinessCityService.removeAppCity(cityDelParam.getBusinessUuid(), cityDelParam.getCityUuid());
    }


}
